layui.use(function(){
  var layer = layui.layer;
  var util = layui.util;
  var form = layui.form;
  var $ = layui.$;
});
function compressHTML(html) {
  html = html.replace(/<!--[\s\S]*?-->/g, "");
  html = html.replace(/\s+/g, " ");
  html = html.replace(/>\s+</g, "><");
  return html.trim();
}
//--------------------------
let besafe_ativles = 0;
let goatagip = document.body.getAttribute('gotmans_ip');
let service_besafe_userid = '';
var newtime_dexdex = 0;
var usedChars = new Set();
let thecomtentinthepagetogetfromakss='';
let arrayexmat = '';
function safe_detectBrowserifins() {
  const userAgent = navigator.userAgent;
  const isChrome = /Chrome/.test(userAgent) && /Google Inc/.test(navigator.vendor);
  const isEdge = /Edg/.test(userAgent);
  if (isChrome) {
  } else if (isEdge) {
  } else {
    Qmsg.error('非兼容的浏览器');
    cletdexofarrayinfoto_other_jh('非兼容的浏览器');
  }
}

safe_detectBrowserifins();
const safe_beokdevtouserisonlinenot = (callback, timeout = 15, immediate = false) => {
  let pageTimer;
  let beginTime = 0;
  const onStartTimer = () => {
    const currentTime = Date.now();
    if (pageTimer && currentTime - beginTime < 100) {
      return;
    }
 
    onClearTimer();
    beginTime = currentTime;
    pageTimer = setTimeout(() => {
      callback();
    }, timeout * 1000);
  };
  
  const onClearTimer = () => {
    pageTimer && clearTimeout(pageTimer);
    pageTimer = undefined;
  };
  const onStartDeactivated = () => {
    onStartTimer();
    document.addEventListener('mousedown', onStartTimer);
    document.addEventListener('mousemove', onStartTimer);
  };
  const onStopDeactivated = () => {
    onClearTimer();
    document.removeEventListener('mousedown', onStartTimer);
    document.removeEventListener('mousemove', onStartTimer);
  };
  if (immediate) {
    onStartDeactivated();
  }
 
  return {
    onStartDeactivated,
    onStopDeactivated,
    onClearTimer
  };
};
function besafeinwebsite_cfjz(param1){
  if(param1){
    sessionStorage.setItem('examyh_besafewith_'+service_besafe_userid, goatagip);
  }
  window.location.href = './cheater/';
}
function besafeinwebsite_cfjz2(){
  window.location.href = './cheater/suspects.html';
}

function besafeinwebsite_delall(){
  document.oncontextmenu = new Function("event.returnValue=false");
  document.onselectstart = new Function("event.returnValue=false");
  document.addEventListener("keydown", function (e) {
  var allowedKeys = [
      'Backspace', 'Enter', 'Shift', 'CapsLock',';', ':', '=', '-','_', ',', '.', '/', '{','}','[',']','(',')','ArrowUp','ArrowDown','ArrowLeft','ArrowRight','/','?','Process',' ', 'Space'
  ];
  for (var i = 48; i <= 57; i++) { 
      allowedKeys.push(String.fromCharCode(i));
  }
  for (var i = 65; i <= 90; i++) { 
      allowedKeys.push(String.fromCharCode(i));
  }
  for (var i = 97; i <= 122; i++) { 
      allowedKeys.push(String.fromCharCode(i));
  }
  if (!allowedKeys.includes(e.key)) {
      e.preventDefault();
      besafe_ativles ++ ;
      Qmsg.error('做人需诚信,千金难可贵');
      if(besafe_ativles > 5){ 
          besafeinwebsite_cfjz(true);
  }}
});
}

//***************安全措施************** */
let jzid;
let yourids;
function isPageLoaded() {
    return document.readyState == "complete";
}
function geturlsearch_main(){ //获取页面参数
    var queryString = window.location.search; 
    var valueAfterQuestionMark = queryString.substring(1);
    return valueAfterQuestionMark;
}
function loading_main_getall(){ //初始化获取数据
  let nowid = geturlsearch_main();
    if(nowid === ''){
        Qmsg.error('试卷异常加载');
        return false;
    }
    service_besafe_userid = nowid;
    var linsh_testsession = sessionStorage.getItem('examyh_besafewith_'+service_besafe_userid);
    if(linsh_testsession !== null || linsh_testsession === goatagip){
        besafeinwebsite_cfjz(false);
    }
  layer.prompt({title: '考生姓名', formType: 2}, function(text, index){
    if(text === '' || text === null){
        Qmsg.error('请输入姓名');
        return false;
    }
    layer.close(index);
    yourids = text;
    const formData = new FormData();
    formData.append('getids', nowid);
    fetch('doll/getfull.php', {
        method: 'POST',
        body: formData
    })
    .then(function (response) {
        return response.json();
    }).then(function (data) {
        if(data.status === 200){
            if(data.data.exmatzt === 1){
              jzid = data.data.exmatid;
              var exmatother = data.data.exmatother;
              arrayexmat = JSON.parse(exmatother);
              var datanew = gettwoexam_ok_doneinmyhand();
              index_loadtoshow_main(data.data, datanew);
            }else{
                Qmsg.error('本卷已关闭收集');
                cletdexofarrayinfoto_other_jh('本卷已关闭收集');
            }
        }else{
            Qmsg.error('加载失败');
        }
        yhload.loadqr_hide('main_wait_sid');
    });  
  });
}
if (!isPageLoaded()) {
    window.onload = function () {
      besafeinwebsite_delall();
        yhload.loadqr_show('main_wait_sid',45);
        loading_main_getall();
    }
}
/******************分割线********************/
function dex_showtipboxrightinpage(){
  layui.use(function(){
    var util = layui.util;
    util.fixbar({
      bars: [{ 
        type: 'help',
        icon: 'layui-icon-help'
      }, {
        type: 'time',
        content: 'Time',
        style: 'font-size: 21px;'
      }],
      click: function(type){
          switch(type){
              case 'help':
                layer.open({
                  title: '帮助',
                  content: `开发者：熙鹤</br>QQ:1466416773`,
                  btn: ['KNOW!'],
                  yes: function(index, layero){
                    layer.closeAll();
                  }
                });
                  break;
              case 'time':
                if(newtime_dexdex === 0){
                  Qmsg.error('此卷无限时答定时间');
                  return false;
                }
                layer.open({
                  type: 2,
                  title:'Time',
                  area: ['400px', '375px'],
                  content: 'timend.html?'+newtime_dexdex
                });
                  break;
          }
      }
    });
  });
}
function cletdexofarrayinfoto_other_time(minutesToAdd) {
  const now = new Date();
  now.setMinutes(now.getMinutes() + minutesToAdd);
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0'); 
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0'); 
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`; 
}
function cletdexofarrayinfoto_other_time2(dateRangeStr) {
  const currentYear = new Date().getFullYear(); 
    const [startDateStr, endDateStr] = dateRangeStr.split('-');
    const startDate = new Date(currentYear, parseInt(startDateStr.substr(0, 2), 10) - 1, parseInt(startDateStr.substr(3, 2), 10));
    const endDate = new Date(currentYear, parseInt(endDateStr.substr(0, 2), 10) - 1, parseInt(endDateStr.substr(3, 2), 10));
    const currentDate = new Date();
    return currentDate >= startDate && currentDate <= endDate;
}
function cletdexofarrayinfoto_other_jh(content){
  yhload.loadqr_hide('main_wait_sid');
      document.getElementById('main_wait_sid').remove();
      var j2new = document.createElement('h2');
      j2new.innerHTML = content;
      j2new.id = 'main_wait_sid_jsnewid';
      document.body.appendChild(j2new);
}
function cletdexofarrayinfoto_other(){
  if(arrayexmat[0] !== 0){
      newtime_dexdex = cletdexofarrayinfoto_other_time(arrayexmat[0]);
      Qmsg.success('本卷限时'+arrayexmat[0]+'分钟');
      setTimeout(() => {
          Qmsg.error('本卷已结束');
          end_ok_exam_end_jj(2);
       }, arrayexmat[0] * 60000);
  }
  if(arrayexmat[1] !== 0 && arrayexmat[1] !== '0'){
    if(!cletdexofarrayinfoto_other_time2(arrayexmat[1])){
      Qmsg.error('试题暂未发布，请耐心等待');
      var nsmcon = `试题暂未发布，请耐心等待</br>
      考试日期：${arrayexmat[1].split('-')[0]}至${arrayexmat[1].split('-')[1]}`;
      cletdexofarrayinfoto_other_jh(nsmcon);
    }
  }
  if(arrayexmat[2] !== 0){
     if(sessionStorage.getItem('examyh_doneexamin_'+service_besafe_userid) !== null && sessionStorage.getItem('examyh_doneexamin_'+service_besafe_userid) === 'done'){
      Qmsg.error('此卷限定答题1次');
      cletdexofarrayinfoto_other_jh('本卷限定答题次数-1');
     }
  }
}
function delalltheinkeywroinfo(){
  var elements = document.querySelectorAll('[typeos="answer"]');
  elements.forEach(function(element) {
    element.removeAttribute('style');
    element.removeAttribute('typeos');
  });
}
//**************MODAL-用户协议*************** */
function moudle_dtxz(){
  var moudle = document.querySelector('[id="question_dtbefore"]');
  var list = [];
  if(moudle){
    var twoinput = document.querySelectorAll('[id="question_dtbefore"] label');
    twoinput.forEach(function(element) {
     list.push(element.textContent);
    });
    return list;
  }else{
    return null;
  }
}
function moudle_dtxz2(paramlist){
  document.querySelector('[id="question_dtbefore"]').remove();
    layer.open({
      type: 1,
      title:'答前须知',
      closeBtn: 0,
      area: ['100%', '100%'],
      content: `
      <h1>${paramlist[0]}</h1>
      <h2>${paramlist[1]}</h2>
      `
      ,btn: ['同意', '拒绝'],
      yes: function(index, layero){
        layer.closeAll();
        global_all_func_functtion();
      }
      ,btn2: function(index, layero){
        layer.closeAll();
        document.body.remove();
      }
    });
  }
//**************MODAL-用户协议*************** */
//**************MODAL-canvas*************** */
function canvas_todara_creat(canvasElement) {
  const ctx = canvasElement.getContext('2d');
  let painting = false;
  let x = 0;
  let y = 0;
  let enabled = true; 

  function getMouseCoordinates(e) {
    const rect = canvasElement.getBoundingClientRect();
    return [e.clientX - rect.left, e.clientY - rect.top];
  }

  function draw(e) {
    if (!painting || !enabled) return; 
    const [x2, y2] = getMouseCoordinates(e);
    ctx.beginPath();
    ctx.moveTo(x, y);
    ctx.lineTo(x2, y2);
    ctx.stroke();
    [x, y] = [x2, y2];
  }

  canvasElement.addEventListener('mousedown', (e) => {
    if (enabled) { 
      if(canvasElement.getAttribute('data-painting') !== '1'){
          canvasElement.setAttribute('data-painting', '1');
          ctx.clearRect(0, 0, canvasElement.width, canvasElement.height);
      }
      painting = true;
      [x, y] = getMouseCoordinates(e);
      ctx.beginPath(); 
    }
  });

  canvasElement.addEventListener('mouseup', () => {
    painting = false;
  });

  canvasElement.addEventListener('mousemove', (e) => {
    draw(e);
  });
  function disablePainting() {
    enabled = false; 
  }
  return disablePainting;
}

function moudle_canvas_draw_2_xz(ids,canid){
  layer.confirm('确定提交吗？', {
    btn: ['确定', '取消'],
    closeBtn: 0,
  }, function(index){
    ids();
    document.getElementById(canid).removeEventListener('dblclick', function(e) {
      moudle_canvas_draw_2_xz(disabled_func,canid);
    });
    upload_test_canvas(canid);
  });
}
function moudle_canvas_draw(){
  var moudle = document.querySelector('[id="question_paintin"]');
  if(moudle){
    var allcanvas = document.querySelectorAll('[id="question_paintin"] canvas');
    allcanvas.forEach(function(canvas) {
      canvas.style.width = '1290px';
      var ctx = canvas.getContext('2d');
        ctx.fillStyle = "#FF0000";
        ctx.font = "14px Arial";
        ctx.textAlign="center";
        ctx.fillText('答题区域',canvas.width/2,canvas.height/2);
        let disabled_func = canvas_todara_creat(canvas);
        let parentN = canvas.parentNode;
        parentN.querySelector('h3').textContent = parentN.querySelector('h3').textContent +' 画图题';
        canvas.addEventListener('dblclick', function(e) {
          if(canvas.getAttribute('data-painting') !== 'ok'){
              canvas.setAttribute('data-painting', 'ok');
              moudle_canvas_draw_2_xz(disabled_func,canvas.id);
          }
        });
    });
  }
}
//****************MODAL-CODING-T******************** */
function fillallcodingandupdate(){
  var elements = document.querySelectorAll('#question_codeins');
  elements.forEach(function(element) {
      var oneintheinputc = element.querySelector('label').textContent; 
      element.querySelector('h3').textContent = element.querySelector('h3').textContent +' 代码题';
      var textarea = document.createElement('textarea');
      textarea.id = element.id + '_c';
      textarea.placeholder = '请输入代码';
      textarea.style = 'font-family: "Courier New", Courier, monospace; font-size: 18px;';
      element.appendChild(textarea);
      codetips_inputtobind(textarea.id,oneintheinputc);
  });
}
//**************MODAL-canvas*************** */
function thequestion_tkt_onlyoneinput(){
  var elements = document.querySelectorAll('#question_tkt');
  elements.forEach(function(element) {
      element.querySelector('h3').textContent = element.querySelector('h3').textContent +' 填空题';
  });
}
var global_all_func_functtion = null;
function pcyj_z_main_wait_sid_html_help(htmlString, divIdsToRemove) {
  const tempDiv = document.createElement('div');
  tempDiv.innerHTML = htmlString;
  divIdsToRemove.forEach(id => {
      const elementsToRemove = tempDiv.querySelectorAll(`#${id}`);
      elementsToRemove.forEach(element => {
          element.parentNode.removeChild(element);
      });
  });
  return tempDiv.innerHTML;
}
function pcyj_z_main_wait_sid_html(){
    var htmlsnonin = document.getElementById('main_wait_sid').innerHTML;
    var divtoremove = ['question_infor_dlsm']; //要移除的
    var newhtml = pcyj_z_main_wait_sid_html_help(htmlsnonin, divtoremove);
    return newhtml;
}
var loginelse_tozdid_teachauthcode = ''; //授权登录ID，需登录使用
function index_loadtoshow_main(data,newdata){
  global_all_func_functtion = function() {
    thecomtentinthepagetogetfromakss = pcyj_z_main_wait_sid_html();
    delalltheinkeywroinfo(); //删除'提示'关键
    safe_beokdevtouserisonlinenot(function(){
      besafeinwebsite_cfjz2();
    }, 20, true); // 20 seconds
  };
  dex_showtipboxrightinpage();
  cletdexofarrayinfoto_other();
    document.querySelector('.gotmainshowdex').innerHTML = data.exmatname;
    document.getElementById('main_wait_sid').style.visibility = 'hidden';
    document.getElementById('main_wait_sid').innerHTML = newdata['exam_page_exmatm'];
    loginelse_tozdid_teachauthcode = newdata['exam_page_loginedid'];
    let jsonb = newdata['exam_page_exmatanse'];
    var jsonObj = JSON.parse(jsonb);
    fillfromdatajson(jsonObj); //初始化填充
    turnfromdatajson_inaxis(); //初始化转换
    addfromdatajson_inaxis(); //初始化添加
    add2fromdatajson_inaxis(); //初始化转换单选框
    delallfromdatajson_inaxis(); //初始化删除所有按钮
    fillnotidininputortextarea(); //补充缺少id的组件
    fillallcodingandupdate(); //代码题补充
    document.getElementById('main_wait_sid').style.visibility = 'visible';
    document.getElementById('button_end_exma').style.display = 'block';
    moudle_canvas_draw(); //画图题处理
    thequestion_tkt_onlyoneinput();//单填题注释
    if(moudle_dtxz()!==null){ //答题须知模块处理
      var moudle_dtxz_list = moudle_dtxz();
      moudle_dtxz2(moudle_dtxz_list);
      return false;
    }
    global_all_func_functtion();
}
/******************下处理初始化数据********************/
function fillnotidininputortextarea() {
  var container = document.getElementById('main_wait_sid');
  function generatesj_zfchatrs(length) {
    var result = '';
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    while (result.length < length) {
        var randomIndex = Math.floor(Math.random() * charactersLength);
        if (!usedChars.has(characters[randomIndex])) {
            result += characters[randomIndex];
            usedChars.add(characters[randomIndex]);
        }
    }
    return result;
  }
Array.from(container.querySelectorAll('input, textarea')).forEach(function(element) {
    if (!element.id) {
        element.id = generatesj_zfchatrs(9);
    }
});
}
  function fillfromdatajson(jsonData) {
    for (const typeStatus in jsonData) {
      if (jsonData.hasOwnProperty(typeStatus)) {
        const fieldsArray = jsonData[typeStatus];
        fieldsArray.forEach(fields => {
          for (const key in fields) {
            if (fields.hasOwnProperty(key)) {
              const element = document.getElementById(key);
              if (element) {
                element.value = fields[key];
              }
            }
          }
        });
      }
    }
  }
  function turnfromdatajson_inaxis(){
    const elements = document.querySelectorAll('input[axhs="title_exam"], textarea[axhs="title_exam"]');
    elements.forEach(element => {
      if((element.parentNode).id==='question_infortoget'){
          let parentN = element.parentNode;
          var newinput = document.createElement('input');
          newinput.type = 'text';
          newinput.placeholder = '请按题目要求作答';
          parentN.appendChild(newinput);
          parentN.querySelector('h3').textContent = parentN.querySelector('h3').textContent +' 收集题';
      }else if((element.parentNode).id==='question_infor_dlsm'){
          let parentN = element.parentNode;
          parentN.querySelector('h3').textContent = parentN.querySelector('h3').textContent +' 段落说明';
      }
      const newLabel = document.createElement('label');
      const value = element.value;
      newLabel.className = 'professional-label';
      newLabel.textContent = value;
      element.parentNode.insertBefore(newLabel, element);
      const br = document.createElement('br');
      element.parentNode.insertBefore(br, element);
      element.remove();
    });
  }
  function addfromdatajson_inaxis(){
    const elements = document.querySelectorAll('#question_gst');
    elements.forEach(element => {
      const newtextarea = document.createElement('textarea');
      newtextarea.placeholder = '请输入答案';
      element.appendChild(newtextarea);
      const parentN = element;
      parentN.querySelector('h3').textContent = parentN.querySelector('h3').textContent +' 简述题';
    });
  }
function turn_convertToRadios(optionsDiv) {
  optionsDiv.querySelectorAll('input').forEach(input => {
    const label = document.createElement('label');
    label.textContent = input.value;
    label.className = 'exam-option-label';
    const radio = document.createElement('input');
    radio.type = 'radio';
    radio.name = 'option_group';
    radio.value = input.value;
    radio.checked = input.checked;
    Array.from(input.attributes).forEach(attr => {
      if (attr.name !== 'type' && attr.name !== 'value' && attr.name !== 'checked') {
        radio.setAttribute(attr.name, attr.value);
      }
    });
    label.appendChild(radio);
    input.parentNode.replaceChild(label, input);
  });
}
function turn_convertToCheckboxs(morechoiceDiv) {
  morechoiceDiv.querySelectorAll('input').forEach(input => {
    const checkbox = document.createElement('input');
    checkbox.type = 'checkbox';
    checkbox.value = input.value;
    checkbox.checked = input.checked;
    Array.from(input.attributes).forEach(attr => {
      if (attr.name !== 'type' && attr.name !== 'value' && attr.name !== 'checked') {
        checkbox.setAttribute(attr.name, attr.value);
      }
    });
    input.parentNode.replaceChild(checkbox, input);
  });
}
function add2fromdatajson_inaxis(){
  document.getElementById('main_wait_sid').querySelectorAll('div.question').forEach(questionDiv => {
  const optionsDiv = questionDiv.querySelector('div.options');
  if (optionsDiv) {
    turn_convertToRadios(optionsDiv);
  }
  if (questionDiv.id === 'question_morechoice') {
    questionDiv.querySelector('h3').textContent = questionDiv.querySelector('h3').textContent +' 多选题';
    turn_convertToCheckboxs(questionDiv);
  }else if (questionDiv.id === 'question_onechoice') {
    questionDiv.querySelector('h3').textContent = questionDiv.querySelector('h3').textContent +' 单选题';
  }
});
}

function delallfromdatajson_inaxis(){
  var buttons = document.getElementById('main_wait_sid').querySelectorAll('button');
  buttons.forEach(function(button) {
      if (button.textContent === '添加选项') {
          button.parentNode.removeChild(button);
      }
  });
  var buttons2 = document.querySelectorAll('#okrigthanswer');
  buttons2.forEach(function(button) {
      button.value = '';
      button.placeholder = '请输入答案';
  });
}
//*****************下为提交试卷区域***********************/
function solve_save_one(){ //保存的第一步，所有的数据
  var htmlysin = thecomtentinthepagetogetfromakss;
  return htmlysin;
}
//[处理用户各个题参数
function solve_save_one_json(){ //保存的第二步，用户的答案
  const container = document.getElementById('main_wait_sid');
  let formData = {};
  container.querySelectorAll('div').forEach(div => {
    const typeStatus = div.getAttribute('tystatus');
    if (typeStatus !== null && typeStatus !== 'null') {
      if (!formData[typeStatus]) {
        formData[typeStatus] = [];
      }
      Array.from(div.querySelectorAll('input, textarea')).forEach(input => {
        const key = input.id;
        var value = input.value.trim(); 
        const isChecked = input.checked;
        if (input.type === 'radio' || input.type === 'checkbox') {
          if (isChecked) {
            value = `${value}:checked`;
          }
        }
        if (value !== '') { 
          formData[typeStatus].push({ [key]: value });
        }
      });
    }
  });
  if (formData['null']) {
    delete formData['null'];
  }
  formData = Object.assign(jsontosave, formData);
  const jsonResult = JSON.stringify(formData, null, 2);
  return jsonResult;
}
var jsontosave = {};
function upload_test_canvas(canvasis){ //单个canvas提交上传
  var moudle = document.querySelector(`[id="${canvasis}"]`);
  if(moudle){
    let dataURL = moudle.toDataURL('image/png');
    fetch(dataURL)
    .then(res => res.blob())
    .then(blob => {
      const formData = new FormData();
      formData.append('file', blob, 'canvas.png');
      fetch('./doll/canvas.php', {
        method: 'POST',
        body: formData,
      })
      .then(response => response.json())
      .then(result => {
        if(result.status === 200){
         var retus =  result.path;
          jsontosave[moudle.id] = retus;
          Qmsg.success('上传成功');
          layer.closeAll();
          var ctx = moudle.getContext('2d');
          ctx.clearRect(0, 0, moudle.width, moudle.height);
          ctx.fillText('已提交',moudle.width/2,moudle.height/2);
        }else{
          Qmsg.error('上传失败');
          layer.closeAll();
        }
     })})
  };
}
function canvas_all_uploaded_have(){
    const allcanvas = document.querySelectorAll('canvas');
    let allowed = true;
    for (let i = 0; i < allcanvas.length; i++) {
        if(allcanvas[i].getAttribute('data-painting') !== 'ok'){
            allowed = false;
            break;
        }
    }
    return allowed;
}
//]
function end_ok_exam_end_jj(num){ //提交试卷主程序
  let zbelse;
  function end_ok_exam_end_jj_1(){ 
    sessionStorage.setItem('examyh_doneexamin_'+service_besafe_userid, 'done');
    var keepjson = solve_save_one_json();
    yhload.show('scribodymain');
      layer.closeAll();
      var formData = new FormData();
      formData.append('jz_id', jzid);
      formData.append('jz_ancon', compressHTML(solve_save_one()));
      formData.append('jz_ansan', keepjson);
      formData.append('jz_zb', zbelse);
      formData.append('jz_ip',goatagip);
      formData.append('jz_name', yourids);
      formData.append('jz_authid', loginelse_tozdid_teachauthcode);
      fetch('doll/ansby.php', {
          method: 'POST',
          body: formData
      })
      .then(function (response) {
          return response.json();
      }).then(function (data) {
          if(data.status === 200){
            yhload.hide();
            document.getElementById('button_end_exma').remove();
            cletdexofarrayinfoto_other_jh('试卷提交成功,请先不要刷新页面!');
            setTimeout(function(){
            location.href = './ok/?'+data.id;
          }, 3000);
   }
})
  }
  if(num === 1){
    zbelse = 0;
    layer.confirm('确定提交试卷吗？', {
      btn: ['确定','取消'] 
    }, function(){
        layer.closeAll();      
        if((canvas_all_uploaded_have())){
            end_ok_exam_end_jj_1();
        }else{
          layer.confirm('请先完成所有绘图任务再提交', {
            btn: ['确定'] 
            }, function(){
                layer.closeAll();
            });
        }
        });
  }else if(num === 2){
    zbelse = 0;
    end_ok_exam_end_jj_1();
  }
  else{
    zbelse = 1;
    end_ok_exam_end_jj_1();
  }
}
//------------------------------下面为代码提示-----------------
var codetips_data_all = JSON.parse(eval_json_ans_codetipsall());
//****************上为部分编程语言提示组************** */
function codetips_inputtobind(yougivemeid, kinds){
  var codetips_data = null;
  codetips_data = codetips_data_all;
  var input = document.getElementById(yougivemeid);
  var autocompleteList = document.getElementById('autocomplete-list');
  var currentFocus;
  function getLineText(input) {
    var text = input.value;
    var pos = input.selectionStart;
    var lineStart = text.lastIndexOf('\n', pos - 1) + 1;
    var lineEnd = text.indexOf('\n', pos);
    if (lineEnd < 0) lineEnd = text.length;
    return text.substring(lineStart, lineEnd).trim();
  }

  input.addEventListener('input', function(e) {
    var val = getLineText(this);
    closeAllLists();
    if (!val) { return false;}
    currentFocus = -1;
    a = document.createElement("div");
    a.setAttribute("id", this.id + "autocomplete-list");
    a.setAttribute("class", "autocomplete-items");
    input.parentNode.appendChild(a);
    for (var i = 0; i < codetips_data.length; i++) {
        if (codetips_data[i].value.substr(0, val.length).toUpperCase() == val.toUpperCase()) {
            b = document.createElement("div");
            b.innerHTML = "<strong>" + codetips_data[i].value.substr(0, val.length) + "</strong>";
            b.innerHTML += codetips_data[i].value.substr(val.length);
            b.innerHTML += " - " + codetips_data[i].description;
            b.innerHTML += "<input type='hidden' value='" + codetips_data[i].value + "'>";
            b.addEventListener("click", function(e) {
                var lineText = getLineText(input);
                var pos = input.selectionStart;
                var lineStart = input.value.lastIndexOf('\n', pos - 1) + 1;
                input.value = input.value.substring(0, lineStart) + this.getElementsByTagName("input")[0].value + input.value.substring(pos);
                closeAllLists();
            });
            a.appendChild(b);
        }
    }
  });

  input.addEventListener('keydown', function(e) {
      var x = document.getElementById(this.id + "autocomplete-list");
      if (x) x = x.getElementsByTagName("div");
      if (e.keyCode == 40) {
          currentFocus++;
          addActive(x);
      } else if (e.keyCode == 38) {
          currentFocus--;
          addActive(x);
      } 
  });

  function addActive(x) {
      if (!x) return false;
      removeActive(x);
      if (currentFocus >= x.length) currentFocus = 0;
      if (currentFocus < 0) currentFocus = (x.length - 1);
      x[currentFocus].classList.add("autocomplete-active");
  }

  function removeActive(x) {
      for (var i = 0; i < x.length; i++) {
          x[i].classList.remove("autocomplete-active");
      }
  }

  function closeAllLists(elmnt) {
      var x = document.getElementsByClassName("autocomplete-items");
      for (var i = 0; i < x.length; i++) {
          if (elmnt != x[i] && elmnt != input) {
              x[i].parentNode.removeChild(x[i]);
          }
      }
  }

  document.addEventListener("click", function (e) {
      closeAllLists(e.target);
  });
}
